package com.itheima.reggie.mapper;

import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Dish;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DishMapper {
    //根据id菜系信息
    @Select("select count(*) from dish where category_id=#{categoryId} and is_deleted=0")
    Integer findById(Long categoryId);

    //添加菜品信息
    @Insert("insert into dish values (null,#{name},#{categoryId},#{price},#{code},#{image}," +
            "#{description},1,1,#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    Integer save(DishDto dishDto);

    //连表查询分页数据
    List<DishDto> findAll2(@Param("name") String name);
    //分表查询分页数据
    List<Dish> findAll(@Param("name") String name);
    //根据菜品id查询一个菜品(一个菜品和多个口味)
    DishDto findById1(Long id);
    //修改菜品信息
    Integer update (DishDto dishDto);
    //根据id获取查询菜品列表数据
    @Select("select * from dish where category_id = #{CategoryId} and is_deleted=0 order by sort asc ")
    List<Dish> findByCategoryId (Long categoryId);
    //根据id查询状态和菜品列表
    @Select("select * from dish where category_id=#{categoryId} and status=#{status} and is_deleted=0 order by sort asc")
    List<Dish> findByCategoryIdAndStatus(@Param("categoryId") Long categoryId,@Param("status") Integer status);
}
